<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<input type="text" class="p1" placeholder="用户名"> <br>
<input type="text" class="p2" placeholder="密码">   <br>
<input type="text" class="p3" placeholder="重复密码（必须和密码一直）"> <br>
<input type="text" class="p4" placeholder="用户名称">
<button>注册</button>
</body>
<script src="./axios.js"></script>
<script>
    var oIpt1=document.querySelector('.p1')
    var oIpt2=document.querySelector('.p2')
    var oIpt3=document.querySelector('.p3')
    var oIpt4=document.querySelector('.p4')
    var oBtn=document.querySelector('button')
    oBtn.onclick=function(){
    axios({
    method:'post',
    url:'http://localhost:8888/users/register',
    headers:{
        "content-type":"application/x-www-form-urlencoded"
    },
    data:{
        username:oIpt1.value,
        password:oIpt2.value,
        rpassword:oIpt3.value,
        nickname:oIpt4.value,
    }
}).then(function(res){
    console.log(res);
    if(res.data.code==1){
        alert("注册成功")
        location.href='登录.html'
    }
    if(res.data.code!=1){
        alert("注册失败")
        return
    }        
})
    }
</script>
</html>